using System;
using System.Text ;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Drawing.Text;
using System.IO;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class CompareValidatorForValuePage : System.Web.UI.Page
{
    string image;
    protected void Page_Load(object sender, EventArgs e)
    {
        image="images/register.gif";
        //image =  "images/USAMap2.jpg";
        string strCompare = "pkmndisae";
        CreateImage(strCompare);
        CompareValidator1.ValueToCompare = strCompare;
        this.Image1.ImageUrl = image;        
    }

    private void CreateImage(string sImageText)
    {
       
        Bitmap ImageSrc = new Bitmap(100, 100);

        int iWidth = 0;
        int iHeight = 0;

         Font myFont = new Font("Verdana", 24,
                           System.Drawing.FontStyle.Bold,
                           System.Drawing.GraphicsUnit.Point);

         Graphics myGraphics = Graphics.FromImage(ImageSrc);

         iWidth = (int)myGraphics.MeasureString(sImageText, myFont).Width;
        iHeight = (int)myGraphics.MeasureString(sImageText, myFont).Height;

         ImageSrc = new Bitmap(ImageSrc, new Size(iWidth, iHeight));

        

         myGraphics = Graphics.FromImage(ImageSrc);
        Rectangle rect = new Rectangle(0, 0, iWidth, iHeight);
        int m = Math.Max(rect.Width, rect.Height);
        HatchBrush hatchBrush = new HatchBrush(
        HatchStyle.SmallConfetti,
        Color.LightGray,
        Color.White);
        Random random = new Random();
        myGraphics.FillRectangle(hatchBrush, rect);
        for (int i = 0; i < (int)(rect.Width * rect.Height / 30F); i++)
        {
            int x = random.Next(rect.Width);
            int y = random.Next(rect.Height);
            int w = random.Next(m / 50);
            int h = random.Next(m / 50);
            myGraphics.FillEllipse(hatchBrush, x, y, w, h);
        }
        myGraphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
        myGraphics.DrawString(sImageText, myFont,
                            new SolidBrush(Color.Gray), 0, 0);
        string imagePath = Server.MapPath(".") + "/" + image;
        //ImageSrc.Save(imagePath, System.Drawing.Imaging.ImageFormat.Gif);
        ImageSrc.Save(imagePath, System.Drawing.Imaging.ImageFormat.Jpeg);
        myGraphics.Flush();
        myGraphics.Dispose();
         
    }
     
}
